package com.zhou.controller;

import com.zhou.bpm.domain.dto.BpmNodeApproverDto;
import com.zhou.bpm.domain.dto.BpmNodeDto;
import com.zhou.bpm.domain.vo.NodeApproverVo;
import com.zhou.bpm.entity.BpmNode;
import com.zhou.bpm.service.IProcessService;
import com.zhou.common.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: zhoujinchuan
 * @Description: TODO（请添加描述）
 * @CreateTime: 2023/10/25 9:38
 */
@RestController
@Api(tags = "流程流程节点")
@RequestMapping("/node")
public class BpmNodeController {

    @Autowired
    private IProcessService processService;

    @GetMapping("/list")
    @ApiOperation("查询流程节点列表")
    public Result<List<BpmNode>> queryProcessNodes(String processCode) {
        List<BpmNode> bpmNodeList = processService.listQueryProcessNode(processCode);
        return Result.success(bpmNodeList);
    }

    @GetMapping("/beforeList")
    @ApiOperation("查询当前节点之前的流程节点列表")
    public Result<List<BpmNode>> queryProcessNodesBeforeList(String processCode, String currentNode) {
        List<BpmNode> bpmNodeList = processService.queryProcessNodesBeforeList(processCode, currentNode);
        return Result.success(bpmNodeList);
    }

    @GetMapping
    @ApiOperation("查询流程节点详情")
    public Result<BpmNode> getByProcessCodeAndNodeCode(String processCode, String nodeCode) {
        BpmNode bpmNodeS = processService.getByProcessCodeAndNodeCode(processCode, nodeCode);
        return Result.success(bpmNodeS);
    }

    @PostMapping
    @ApiOperation("新增流程节点")
    public Result<BpmNode> addProcessNode(@RequestBody @Validated BpmNodeDto dto) {
        BpmNode bpmNode = processService.addProcessNode(dto);
        return Result.success(bpmNode);
    }

    @PutMapping
    @ApiOperation("修改流程节点")
    public Result<BpmNode> modifyProcess(@RequestBody @Validated BpmNodeDto dto) {
        BpmNode bpmNode = processService.modifyProcessNode(dto);
        return Result.success(bpmNode);
    }

    @DeleteMapping
    @ApiOperation("删除流程节点")
    public Result deleteProcessNode(String processCode, String nodeCode) {
        processService.deleteProcessNode(processCode, nodeCode);
        return Result.ok();
    }

    @GetMapping("/approver")
    @ApiOperation("查询流程节点审批人")
    public Result<List<NodeApproverVo>> queryNodeApprover(String processCode, String nodeCode) {
        List<NodeApproverVo> resultList = processService.listQueryNodeApprover(processCode, nodeCode);
        return Result.success(resultList);
    }

    @PostMapping("/approver")
    @ApiOperation("调整流程节点审批人（传null就是删除）")
    public Result adjustmentNodeApprover(@RequestBody @Validated BpmNodeApproverDto dto) {
        processService.adjustmentNodeApprover(dto);
        return Result.ok();
    }


}
